package com.jhg.drgclinicalpathway.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jhg.drgclinicalpathway.dao.sys.SysOpsDao;
import com.jhg.drgclinicalpathway.domain.SysOps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 自定义定时任务
 */
@Slf4j
@Component
public class MyTask {

    @Autowired
    SysOpsDao sysOpsDao;

    @Scheduled(fixedRateString = "${scheduledTask.sysops.fixedRate}")
    public void 自动删除访问日志() {
        QueryWrapper<SysOps> queryWrapper = new QueryWrapper<SysOps>();
        Date date = new Date();
        Long l = date.getTime() - 7 * 24 * 60 * 60 * 1000;
        String t = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(l));
        queryWrapper.lt("ctime", t);
        int delete = sysOpsDao.delete(queryWrapper);
        log.info("自动删x<" + t + "的记录" + delete + "条");
    }
}
